function initStundenplan(){
	//console.log("ac");
	
	/*console.log("faeacherTest: " + jsonArrayFaecher["MAD"][0].row);
	console.log("faeacherTest: " + jsonArrayFaecher["MAD"][0].column);
	console.log("faeacherTest: " + jsonArrayFaecher["MAD"][0].room);*/
	

	buildStundenplan();
	
	findFaecherAt(1,3);
}



$(document).delegate("#stundenplan_aendern", "pageinit", function() {
	
	
	buildStundenplanAendernList();
	
});



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Click-Events


$(document).delegate('.stae_faecher', 'click', function () {
	
    
    if($(this).attr("data-icon") == "plus"){
    	
    	
    	$('#'+this.id).buttonMarkup({ icon: "minus" }).trigger("create");
    	jsonArraybelegteFaecher[this.id] = false;
    	//console.log("MDI belegt: " + jsonArraybelegteFaecher[this.id]);
    	
    }else{
    	
    	$('#'+this.id).buttonMarkup({ icon: "plus" }).trigger("create");
    	jsonArraybelegteFaecher[this.id] = true;
    	//console.log("MDI belegt: " + jsonArraybelegteFaecher[this.id]);
    }
    
});



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// functions

/*
 * 	Bildet das HTML Content von der StundenPlan Page, als Grid View auf
 */
function buildStundenplan(){
	
	
	var HTMLAsString = "";
	
	HTMLAsString = 
		'<div class="ui-block-a stundenplan-table-header"><div class="stundenplan-tableHeaderContent">Mo</div></div>'+
        '<div class="ui-block-b stundenplan-table-header"><div class="stundenplan-tableHeaderContent">Di</div></div>'+
        '<div class="ui-block-c stundenplan-table-header"><div class="stundenplan-tableHeaderContent">Mi</div></div>'+
        '<div class="ui-block-d stundenplan-table-header"><div class="stundenplan-tableHeaderContent">Do</div></div>'+
        '<div class="ui-block-e stundenplan-table-header"><div class="stundenplan-tableHeaderContent">Fr</div></div>';
	
	for(var i = 1; i <= 6; i++){
		
		HTMLAsString = HTMLAsString +
			'<div class="ui-block-a stundenplan-table-block">'+getFaecherHTML(i, 1)+'</div>'+
	        '<div class="ui-block-b stundenplan-table-block">'+getFaecherHTML(i, 2)+'</div>'+
	        '<div class="ui-block-c stundenplan-table-block">'+getFaecherHTML(i, 3)+'</div>'+
	        '<div class="ui-block-d stundenplan-table-block">'+getFaecherHTML(i, 4)+'</div>'+
	        '<div class="ui-block-e stundenplan-table-block">'+getFaecherHTML(i, 5)+'</div>';
	}
	
	$('#stundentplan_table').empty().append(HTMLAsString).trigger("create");
}


/*
 * gibt eine HTML Zeile zurück, die entweder die Informationen des Faches (falls es existiert und belegt ist) 
 * oder keine Information beinhaltet.
 * 
 * @param row
 * Die Zeile des Stundenplans (1 bis 6)
 * 
 * @param column
 * Die Spalte des Stundenplans (1 bis 5)
 */
function getFaecherHTML(row, column){
	
	var fach = findFaecherAt(row, column);
	
	if(fach != null && jsonArraybelegteFaecher[fach["name"]]){
		
		return '<div class="stundenplan-tableBlockContent">'+fach["name"]+'</div><div class="stundenplan-tableBlockSubContent">'+fach["room"]+'</div>';
		
	}else{
		
		return '<div class="stundenplan-tableBlockContent">-</div>';
	}
}



/*
 * gibt eine JSON zurück, die entweder die Informationen des Faches (falls es existiert) 
 * oder keine Information beinhaltet.
 * 
 * @param row
 * Die Zeile des Stundenplans (1 bis 6)
 * 
 * @param column
 * Die Spalte des Stundenplans (1 bis 5)
 */
function findFaecherAt(row, column){
	
	var fach = null;
	
	$.each(jsonArrayFaecher, function(i, val) {
		
		$.each(val, function() {
			
			if(this.row == row && this.column == column){
				
				fach =  {"name": i, "room":this.room};
			}
		});
	});
	

	return fach;
}


/*
 * Bildet das HTML Content von der stundenPlan_aendern Page, als List-View auf
 */
function buildStundenplanAendernList(){
	
	
	var HTMLAsString = "";
	
	HTMLAsString = 
		
					'<div id="stae_informatik" data-role="collapsible" data-theme="b" class="stae_faecherListe">'+
				    
				    	'<h3>Informatik</h3>'+
				    
					    '<ul data-role="listview" data-theme="e">'+
					        '<li id="MDI" data-icon="'+ getPlusMinusIcon("MDI") +'" class="stae_faecher"><a href="#">6.SEM  -  MDI</a></li>'+
					        '<li id="IPP" data-icon="'+ getPlusMinusIcon("IPP") +'" class="stae_faecher"><a href="#">6.SEM  -  IPP</a></li>'+
					        '<li id="SEU" data-icon="'+ getPlusMinusIcon("SEU") +'" class="stae_faecher"><a href="#">7.SEM  -  SEU</a></li>'+
					        '<li id="AGI" data-icon="'+ getPlusMinusIcon("AGI") +'" class="stae_faecher"><a href="#">7.SEM  -  AGI</a></li>'+
					     '</ul>'+
					'</div>'+
					
					'<div id="stae_design" data-role="collapsible" data-theme="b" class="stae_faecherListe">'+
					               
					    '<h3>Design</h3>'+
					    
					    '<ul data-role="listview" data-theme="e">'+
					        '<li id="VND" data-icon="'+ getPlusMinusIcon("VND") +'" class="stae_faecher"><a href="#">3.SEM  -  VND</a></li>'+
					        '<li id="VID" data-icon="'+ getPlusMinusIcon("VID") +'" class="stae_faecher"><a href="#">3.SEM  -  VID</a></li>'+
					        '<li id="MAD" data-icon="'+ getPlusMinusIcon("MAD") +'" class="stae_faecher"><a href="#">4.SEM  -  MAD</a></li>'+
					        '<li id="POOL" data-icon="'+ getPlusMinusIcon("POOL") +'" class="stae_faecher"><a href="#">4.SEM  -  POOL</a></li>'+
					     '</ul>'+
					'</div>'+
					
					'<div id="stae_sonstiges" data-role="collapsible" data-theme="b" class="stae_faecherListe">'+
					               
					    '<h3>Sonstiges</h3>'+
					    
					    '<ul data-role="listview" data-theme="e">'+
					        '<li id="SPC" data-icon="'+ getPlusMinusIcon("SPC") +'" class="stae_faecher"><a href="#">5.SEM  -  SPC</a></li>'+
					     '</ul>'+
					'</div>';
	
	
	$('#stae_content').empty().append(HTMLAsString).trigger("create");

}


/*
 * überprüft oder das Fach mit der ID beleget ist. Wenn ja, dann
 * gibt den String mit den Wert "plus" und wenn Nein "minus" zurück.
 * 
 * @param id
 * ID des Faches bzw. den Wert, das auch im jsonArraybelegteFaecher ist
 */
function getPlusMinusIcon(id){
	
	if(jsonArraybelegteFaecher[id] == true){
		
		return "plus";
	}else{
		return "minus";
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//json's

var jsonArraybelegteFaecher = {
        

	 	"MDI":true
	 				
	 ,
	 
	 	"SPC":true
		 				
	 ,
	 
	 	"VND":true
		 				
	 ,
	 
	 	"IPP":true
		 				
	 ,
	 
	 	"POOL":true
	 				
	 ,
	 
	 	"VID":true
		 				
	 ,
	 
	 	"SEU":false
		 				
	 ,
	 
	 	"AGI":false
		 				
	 ,
	 
		 "MAD":false
		 				
};

var jsonArrayFaecher = {
                 

		
 	"MDI":[
           	{"row":1, "column":3, "room":"A008" },
           	{"row":3, "column":4, "room":"A210" }
           ]
 				
 ,
 
 	"SPC":[
           	{"row":2, "column":2, "room":"L003" },
           	{"row":4, "column":5, "room":"L003" }
           ]
	 				
 ,
 
 	"VND":[
           	{"row":5, "column":1, "room":"Z105" },
           	{"row":6, "column":1, "room":"Z105" }
           ]
	 				
 ,
 
 	"IPP":[
           	{"row":5, "column":3, "room":"Z212" },
           	{"row":3, "column":5, "room":"A008" }
           ]
	 				
 ,
 
 	"POOL":[
           	{"row":6, "column":3, "room":"Z212" }
           ]
 				
 ,
 
 	"VID":[
           	{"row":5, "column":4, "room":"Z103" },
           	{"row":6, "column":4, "room":"Z103" }
           ]
	 				
 ,
 
 	"SEU":[
           	{"row":3, "column":3, "room":"A005" },
           	{"row":4, "column":4, "room":"A210" }
           ]
	 				
 ,
 
 	"AGI":[
           	{"row":1, "column":1, "room":"A008" },
           	{"row":2, "column":6, "room":"A210" }
           ]
	 				
 ,
 
	 
	 "MAD":[
	       	{"row":4, "column":2, "room":"Z002" },
	       	{"row":5, "column":2, "room":"Z002" }
	       ]
	 				
};